package com.guldan.thrall.web.controller;

import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.response.ResponseJson;
import com.guldan.jaina.dto.datastat.report.MoneyStatDTO;
import com.guldan.jaina.dto.datastat.report.ReportSearchDTO;
import com.guldan.jaina.dto.datastat.report.SubsidyGrantStatDTO;
import com.guldan.jaina.dto.report.Point;
import com.guldan.jaina.dto.report.Points;
import com.guldan.jaina.provider.IReportProvider;
import com.guldan.thrall.common.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Silas.
 * Date: 2017/1/23
 * Time: 12:57
 */
@Controller
@RequestMapping("/visualization")
public class VisualizationController extends BaseController {

    @Autowired
    private IReportProvider iReportProvider;


    //数据可视化+++++++++++++++
    //补贴发放统计

    //金额统计
    @RequestMapping(value = "/register/getMoneyStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getMoneyStat(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<MoneyStatDTO>> responseDTO = iReportProvider.getMoneyStat(search);

        List<Points> pointsList = new ArrayList<>();
        Points points = new Points();
        List<Point> pointList = new ArrayList<>();
        for (MoneyStatDTO dto : responseDTO.getData()) {
            pointList.add(new Point(dto.getDateStr(), dto.getTotal().doubleValue()));
        }
        points.setName("补贴金额");
        points.setPointList(pointList);

        pointsList.add(points);

        return pointsList;
    }

    //人次统计
    @RequestMapping(value = "/register/getPersonStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getPersonStat(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getPersonStat(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points(), points2 = new Points();
        List<Point> pointList1 = new ArrayList<>(), pointList2 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getDateStr(), dto.getPersonTotal().doubleValue()));  //人次
            pointList2.add(new Point(dto.getDateStr(), dto.getPersonCount().doubleValue()));  //人数
        }
        points1.setName("覆盖人次");
        points1.setPointList(pointList1);

        points2.setName("覆盖人数");
        points2.setPointList(pointList2);

        pointsList.add(points1);
        pointsList.add(points2);

        return pointsList;
    }

    //发放情况统计-按区划(柱状+折线)
    @RequestMapping(value = "/register/getSubsidyGrantStatForArea", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getSubsidyGrantStatForArea(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getSubsidyGrantStatForArea(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points(), points2 = new Points(), points3 = new Points();
        List<Point> pointList1 = new ArrayList<>(), pointList2 = new ArrayList<>(), pointList3 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getAreaStr(), dto.getPersonTotal().doubleValue()));  //人次
            pointList2.add(new Point(dto.getAreaStr(), dto.getPersonCount().doubleValue()));  //人数
            pointList3.add(new Point(dto.getAreaStr(), dto.getMoneyTotal().doubleValue()));   //补贴金额
        }
        points1.setName("覆盖人次");
        points1.setPointList(pointList1);

        points2.setName("覆盖人数");
        points2.setPointList(pointList2);

        points3.setName("补贴金额");
        points3.setPointList(pointList3);

        pointsList.add(points1);
        pointsList.add(points2);
        pointsList.add(points3);

        return pointsList;
    }

    //发放情况统计-按项目(柱状+折线)
    @RequestMapping(value = "/register/getSubsidyGrantStatForProject", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getSubsidyGrantStatForProject(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getSubsidyGrantStatForProject(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points(), points2 = new Points(), points3 = new Points();
        List<Point> pointList1 = new ArrayList<>(), pointList2 = new ArrayList<>(), pointList3 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getProjectStr(), dto.getMoneyTotal().doubleValue()));  //金额
            pointList2.add(new Point(dto.getProjectStr(), dto.getPersonTotal().doubleValue()));  //人次
            pointList3.add(new Point(dto.getProjectStr(), dto.getPersonCount().doubleValue()));  //人数
        }
        points1.setName("补贴金额");
        points1.setPointList(pointList1);

        points2.setName("覆盖人次");
        points2.setPointList(pointList2);

        points3.setName("覆盖人数");
        points3.setPointList(pointList3);

        pointsList.add(points1);
        pointsList.add(points2);
        pointsList.add(points3);

        return pointsList;
    }


    //覆盖人次性别统计
    @RequestMapping(value = "/register/getGenderStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getGenderStat(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getGenderStat(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points();
        List<Point> pointList1 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getGenderStr(), dto.getPersonTotal().doubleValue()));
        }
        points1.setName("覆盖人次性别统计");
        points1.setPointList(pointList1);

        pointsList.add(points1);

        return pointsList;
    }

    //覆盖人次民族统计
    @RequestMapping(value = "/register/getNationStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getNationStat(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getNationStat(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points();
        List<Point> pointList1 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getNationStr(), dto.getPersonTotal().doubleValue()));
        }
        points1.setName("覆盖人次民族统计");
        points1.setPointList(pointList1);

        pointsList.add(points1);

        return pointsList;
    }


    //受益年龄统计
    @RequestMapping(value = "/register/getBenefitAgeStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getBenefitAgeStat(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getBenefitAgeStat(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points();
        List<Point> pointList1 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getAgeStr(), dto.getPersonTotal().doubleValue()));
        }
        points1.setName("受益年龄人次统计");
        points1.setPointList(pointList1);

        pointsList.add(points1);

        return pointsList;
    }


    //人员性别统计
    @RequestMapping(value = "/citizen/getGenderStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getGenderStatForCitzen(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getGenderStatForCitzen(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points();
        List<Point> pointList1 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getGenderStr(), dto.getPersonCount().doubleValue()));
        }
        points1.setName("人员性别统计");
        points1.setPointList(pointList1);

        pointsList.add(points1);

        return pointsList;
    }

    //人员民族统计
    @RequestMapping(value = "/citizen/getNationStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getNationStatForCitzen(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getNationStatForCitzen(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points();
        List<Point> pointList1 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getNationStr(), dto.getPersonCount().doubleValue()));
        }
        points1.setName("人员民族统计");
        points1.setPointList(pointList1);

        pointsList.add(points1);

        return pointsList;
    }

    //人员信息统计 - 年龄结构
    @RequestMapping(value = "/citizen/getAgeStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getAgeStatForCitzen(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getAgeStatForCitzen(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points();
        List<Point> pointList1 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getAgeStr(), dto.getPersonTotal().doubleValue()));
        }
        points1.setName("年龄结构人数");
        points1.setPointList(pointList1);

        pointsList.add(points1);

        return pointsList;
    }

    //人员信息统计 - 区划人数
    @RequestMapping(value = "/citizen/getAreaPersonStat", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<Points> getAreaPersonStatForCitzen(@RequestBody ReportSearchDTO search) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = iReportProvider.getAreaPersonStatForCitzen(search);

        List<Points> pointsList = new ArrayList<>();
        Points points1 = new Points();
        List<Point> pointList1 = new ArrayList<>();
        for (SubsidyGrantStatDTO dto : responseDTO.getData()) {
            pointList1.add(new Point(dto.getAreaStr(), dto.getPersonCount().doubleValue()));  //人数
        }
        points1.setName("区划人数");
        points1.setPointList(pointList1);

        pointsList.add(points1);

        return pointsList;
    }

}
